package com.ruoyi.ftrl.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ftrl.domain.CommunityInfo;
import com.ruoyi.ftrl.domain.Dto.CommunityDto;
import com.ruoyi.ftrl.domain.HeatStation;
import com.ruoyi.ftrl.service.ICommunityInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 小区管理信息Controller
 * 
 * @author dihang
 * @date 2024-07-08
 */
@RestController
@RequestMapping("/ftrl/info")
public class CommunityInfoController extends BaseController
{
    @Autowired
    private ICommunityInfoService communityInfoService;

    /**
     * 供热质量（大屏驾驶舱）
     * @return
     */
    @GetMapping("/hot")
    public TableDataInfo getHot()
    {
      List<CommunityDto>communityDtoList=communityInfoService.selectCommunityInfoListHot();
        return getDataTable(communityDtoList) ;
    }

    /**
     * 供热概况（大屏驾驶舱）
     */
    @GetMapping(value = "/heat")
    public AjaxResult getHeatInfo()
    {
        return success(communityInfoService.selectCommunityInfo());
    }


    /**
     * 根据热力站id查询子级小区列表
     */
    @GetMapping(value = "/Community/{id}")
    public TableDataInfo getInfos(@PathVariable("id") Long id)
    {
       List<CommunityInfo>communityInfoList=communityInfoService.selectCommunityInfoLists(id);
        return getDataTable(communityInfoList) ;
    }

    /**
     * 小区管理（根据热力站id查询）GIS模块
     */
    @GetMapping(value = "/gis/{id}")
    public TableDataInfo getInfoGis(@PathVariable("id") Long id)
    {
        List<CommunityInfo>communityInfoList=communityInfoService.selectCommunityInfoListGIS(id);
        return getDataTable(communityInfoList) ;
    }

    /**
     * 查询小区管理信息列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityInfo communityInfo)
    {
        startPage();
        List<CommunityInfo> list = communityInfoService.selectCommunityInfoList(communityInfo);
        return getDataTable(list);
    }

    /**
     * 导出小区管理信息列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:info:export')")
    @Log(title = "小区管理信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityInfo communityInfo)
    {
        List<CommunityInfo> list = communityInfoService.selectCommunityInfoList(communityInfo);
        ExcelUtil<CommunityInfo> util = new ExcelUtil<CommunityInfo>(CommunityInfo.class);
        util.exportExcel(response, list, "小区管理信息数据");
    }

    /**
     * 获取小区管理信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(communityInfoService.selectCommunityInfoById(id));
    }

    /**
     * 新增小区管理信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:info:add')")
    @Log(title = "小区管理信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityInfo communityInfo)
    {
        return toAjax(communityInfoService.insertCommunityInfo(communityInfo));
    }

    /**
     * 修改小区管理信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:info:edit')")
    @Log(title = "小区管理信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityInfo communityInfo)
    {
        return toAjax(communityInfoService.updateCommunityInfo(communityInfo));
    }

    /**
     * 删除小区管理信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:info:remove')")
    @Log(title = "小区管理信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(communityInfoService.deleteCommunityInfoByIds(ids));
    }
}
